import { exportExcel, importExcel } from '@/api/excel'

const getDefaultState = () => {}

const state = getDefaultState()

const mutations = {}

const actions = {
  //导入excel
  async importExcel({ commit, state }, { url, file }) {
    return new Promise((resolve, reject) => {
      var form = new FormData()
      form.append('excel', file.raw === undefined ? file : file.raw)
      importExcel(url, form)
        .then((response) => {
          resolve(response)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },

  //导出excel
  async exportExcel({ commit, state }, url) {
    return new Promise((resolve, reject) => {
      exportExcel(url)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
